package com.liush.srb.core.controller.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liush.srb.base.result.ResponseVo;
import com.liush.srb.core.pojo.entity.Lend;
import com.liush.srb.core.pojo.vo.LendInfoVO;
import com.liush.srb.core.pojo.vo.LendSearchVO;
import com.liush.srb.core.service.LendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * <p>
 * 标的准备表 前端控制器
 * </p>
 *
 * @author liush
 * @since 2023-04-11
 */
@Api(tags = "api标的准备模块")
@RestController
@RequestMapping("/api/core/lend")
public class ApiLendController {

    @Resource
    LendService lendService;

    @ApiOperation("会员条件查询标的列表")
    @GetMapping("list/{pageNum}/{pageSize}")
    public ResponseVo list(LendSearchVO lendSearchVO,
                           @PathVariable("pageNum") Integer pageNum,
                           @PathVariable("pageSize") Integer pageSize) {//pojo入参
        Page<Lend> page = lendService.getLendsByCondition(lendSearchVO, pageNum, pageSize);
        return ResponseVo.ok().data("page", page);
    }

    @ApiOperation("查询标的详情")
    @GetMapping("{id}")
    public ResponseVo getById(@PathVariable("id") Long id) {
        LendInfoVO lendInfoVO = lendService.getLendInfoVOById(id);
        return ResponseVo.ok().data("item", lendInfoVO);
    }

    @ApiOperation("计算投资收益")
    @GetMapping("/income/{amount}/{lendYearRate}/{period}/{returnMethod}") // 投资金额、标的年化率、期数、还款方式
    public ResponseVo income(@PathVariable("amount") BigDecimal amount,
                             @PathVariable("lendYearRate") BigDecimal lendYearRate,
                             @PathVariable("period") Integer period,
                             @PathVariable("returnMethod") Integer returnMethod) {
        BigDecimal income = lendService.income(amount, lendYearRate, period, returnMethod);
        return ResponseVo.ok().data("income", income);
    }
}